/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ru.miit.elearning.vtutor.check.object;

import java.util.logging.Level;
import java.util.logging.Logger;
import ru.miit.elearning.vtutor.data.CheckObject;
import ru.miit.elearning.vtutor.ftp.FTPClientDecorator;

/**
 *
 * @author Cyclone
 */
public class CheckObjectPDSChapterType extends CheckObjectPSType {
    CheckObjectPDSChapterType(CheckObject co) {
        super(co);
    }

    @Override
    protected boolean isObjectListed(FTPClientDecorator ftp) {
        boolean chapterFound = false;
        try {
            String[] pathParts = path.split("\\(");
            // String psPath = pathParts[0];
            String chapterName = pathParts[1].split("\\)")[0];
            String[] list = ftp.listPDS(pathParts[0]);

            if (list != null) {
                for (String name : list) {
                    if (name.equalsIgnoreCase(chapterName)) {
                        chapterFound = true;
                        break;
                    }
                }
            }
        } catch (Exception e) {
            Logger.getLogger(CheckObjectPSType.class.getName()).log(Level.SEVERE, null, e);
            e.printStackTrace();
        }
        return chapterFound;
    }
}
